package com.iandun.web.framework.core.utils.bean;

import io.vavr.control.Try;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * 属性拷贝
 *
 * @author :jason.liang
 * @date: 2021-05-21 15:38
 */
@Slf4j
public class BeanCopyUtils {

    public static <T> T copy(Object source, T target) {
        return Try.of(() -> {
            if (source == null || target == null) {
                return null;
            } else {
                BeanUtils.copyProperties(source, target);
                return target;
            }
        }).onFailure(e -> {
            log.error("BeanCopyUtils Value copy exception->{}", e.getMessage());
        }).get();
    }
}
